home *** CD-ROM | disk | FTP | other *** search
/ Kellogg's Amérique / Kellogg's Amérique / amazonie_en_danger.swf / scripts / fl / controls / TextInput.as < prev   
Text File  |  2020-08-04  |  11KB  |  410 lines

  1. package fl.controls
  2. {
  3.    import fl.core.InvalidationType;
  4.    import fl.core.UIComponent;
  5.    import fl.events.ComponentEvent;
  6.    import fl.managers.IFocusManager;
  7.    import fl.managers.IFocusManagerComponent;
  8.    import flash.display.DisplayObject;
  9.    import flash.events.Event;
  10.    import flash.events.FocusEvent;
  11.    import flash.events.KeyboardEvent;
  12.    import flash.events.TextEvent;
  13.    import flash.text.TextField;
  14.    import flash.text.TextFieldType;
  15.    import flash.text.TextFormat;
  16.    import flash.text.TextLineMetrics;
  17.    import flash.ui.Keyboard;
  18.    
  19.    public class TextInput extends UIComponent implements IFocusManagerComponent
  20.    {
  21.       
  22.       private static var defaultStyles:Object = {
  23.          "upSkin":"TextInput_upSkin",
  24.          "disabledSkin":"TextInput_disabledSkin",
  25.          "focusRectSkin":null,
  26.          "focusRectPadding":null,
  27.          "textFormat":null,
  28.          "disabledTextFormat":null,
  29.          "textPadding":0,
  30.          "embedFonts":false
  31.       };
  32.       
  33.       public static var createAccessibilityImplementation:Function;
  34.        
  35.       
  36.       protected var _html:Boolean = false;
  37.       
  38.       protected var _savedHTML:String;
  39.       
  40.       protected var background:DisplayObject;
  41.       
  42.       protected var _editable:Boolean = true;
  43.       
  44.       public var textField:TextField;
  45.       
  46.       public function TextInput()
  47.       {
  48.          _editable = true;
  49.          _html = false;
  50.          super();
  51.       }
  52.       
  53.       public static function getStyleDefinition() : Object
  54.       {
  55.          return defaultStyles;
  56.       }
  57.       
  58.       override public function drawFocus(param1:Boolean) : void
  59.       {
  60.          if(focusTarget != null)
  61.          {
  62.             focusTarget.drawFocus(param1);
  63.             return;
  64.          }
  65.          super.drawFocus(param1);
  66.       }
  67.       
  68.       public function set imeMode(param1:String) : void
  69.       {
  70.          _imeMode = param1;
  71.       }
  72.       
  73.       override protected function isOurFocus(param1:DisplayObject) : Boolean
  74.       {
  75.          return param1 == textField || super.isOurFocus(param1);
  76.       }
  77.       
  78.       protected function handleKeyDown(param1:KeyboardEvent) : void
  79.       {
  80.          if(param1.keyCode == Keyboard.ENTER)
  81.          {
  82.             dispatchEvent(new ComponentEvent(ComponentEvent.ENTER,true));
  83.          }
  84.       }
  85.       
  86.       public function set text(param1:String) : void
  87.       {
  88.          textField.text = param1;
  89.          _html = false;
  90.          invalidate(InvalidationType.DATA);
  91.          invalidate(InvalidationType.STYLES);
  92.       }
  93.       
  94.       protected function updateTextFieldType() : void
  95.       {
  96.          textField.type = enabled && editable ? TextFieldType.INPUT : TextFieldType.DYNAMIC;
  97.          textField.selectable = enabled;
  98.       }
  99.       
  100.       public function get selectionEndIndex() : int
  101.       {
  102.          return textField.selectionEndIndex;
  103.       }
  104.       
  105.       public function get editable() : Boolean
  106.       {
  107.          return _editable;
  108.       }
  109.       
  110.       override protected function focusInHandler(param1:FocusEvent) : void
  111.       {
  112.          var _loc2_:IFocusManager = null;
  113.          if(param1.target == this)
  114.          {
  115.             stage.focus = textField;
  116.          }
  117.          _loc2_ = focusManager;
  118.          if(editable && _loc2_)
  119.          {
  120.             _loc2_.showFocusIndicator = true;
  121.             if(textField.selectable && textField.selectionBeginIndex == textField.selectionBeginIndex)
  122.             {
  123.                setSelection(0,textField.length);
  124.             }
  125.          }
  126.          super.focusInHandler(param1);
  127.          if(editable)
  128.          {
  129.             setIMEMode(true);
  130.          }
  131.       }
  132.       
  133.       public function get selectionBeginIndex() : int
  134.       {
  135.          return textField.selectionBeginIndex;
  136.       }
  137.       
  138.       public function set alwaysShowSelection(param1:Boolean) : void
  139.       {
  140.          textField.alwaysShowSelection = param1;
  141.       }
  142.       
  143.       override public function set enabled(param1:Boolean) : void
  144.       {
  145.          super.enabled = param1;
  146.          updateTextFieldType();
  147.       }
  148.       
  149.       protected function setEmbedFont() : *
  150.       {
  151.          var _loc1_:Object = null;
  152.          _loc1_ = getStyleValue("embedFonts");
  153.          if(_loc1_ != null)
  154.          {
  155.             textField.embedFonts = _loc1_;
  156.          }
  157.       }
  158.       
  159.       public function get horizontalScrollPosition() : int
  160.       {
  161.          return textField.scrollH;
  162.       }
  163.       
  164.       public function set condenseWhite(param1:Boolean) : void
  165.       {
  166.          textField.condenseWhite = param1;
  167.       }
  168.       
  169.       public function set displayAsPassword(param1:Boolean) : void
  170.       {
  171.          textField.displayAsPassword = param1;
  172.       }
  173.       
  174.       public function set horizontalScrollPosition(param1:int) : void
  175.       {
  176.          textField.scrollH = param1;
  177.       }
  178.       
  179.       public function get restrict() : String
  180.       {
  181.          return textField.restrict;
  182.       }
  183.       
  184.       public function get textWidth() : Number
  185.       {
  186.          return textField.textWidth;
  187.       }
  188.       
  189.       public function get textHeight() : Number
  190.       {
  191.          return textField.textHeight;
  192.       }
  193.       
  194.       public function set editable(param1:Boolean) : void
  195.       {
  196.          _editable = param1;
  197.          updateTextFieldType();
  198.       }
  199.       
  200.       public function get maxChars() : int
  201.       {
  202.          return textField.maxChars;
  203.       }
  204.       
  205.       public function get length() : int
  206.       {
  207.          return textField.length;
  208.       }
  209.       
  210.       public function getLineMetrics(param1:int) : TextLineMetrics
  211.       {
  212.          return textField.getLineMetrics(param1);
  213.       }
  214.       
  215.       public function get imeMode() : String
  216.       {
  217.          return _imeMode;
  218.       }
  219.       
  220.       override protected function focusOutHandler(param1:FocusEvent) : void
  221.       {
  222.          super.focusOutHandler(param1);
  223.          if(editable)
  224.          {
  225.             setIMEMode(false);
  226.          }
  227.       }
  228.       
  229.       public function set htmlText(param1:String) : void
  230.       {
  231.          if(param1 == "")
  232.          {
  233.             text = "";
  234.             return;
  235.          }
  236.          _html = true;
  237.          _savedHTML = param1;
  238.          textField.htmlText = param1;
  239.          invalidate(InvalidationType.DATA);
  240.          invalidate(InvalidationType.STYLES);
  241.       }
  242.       
  243.       public function get text() : String
  244.       {
  245.          return textField.text;
  246.       }
  247.       
  248.       override public function get enabled() : Boolean
  249.       {
  250.          return super.enabled;
  251.       }
  252.       
  253.       public function get condenseWhite() : Boolean
  254.       {
  255.          return textField.condenseWhite;
  256.       }
  257.       
  258.       public function get alwaysShowSelection() : Boolean
  259.       {
  260.          return textField.alwaysShowSelection;
  261.       }
  262.       
  263.       override protected function draw() : void
  264.       {
  265.          var _loc1_:Object = null;
  266.          if(isInvalid(InvalidationType.STYLES,InvalidationType.STATE))
  267.          {
  268.             drawTextFormat();
  269.             drawBackground();
  270.             _loc1_ = getStyleValue("embedFonts");
  271.             if(_loc1_ != null)
  272.             {
  273.                textField.embedFonts = _loc1_;
  274.             }
  275.             invalidate(InvalidationType.SIZE,false);
  276.          }
  277.          if(isInvalid(InvalidationType.SIZE))
  278.          {
  279.             drawLayout();
  280.          }
  281.          super.draw();
  282.       }
  283.       
  284.       protected function handleTextInput(param1:TextEvent) : void
  285.       {
  286.          param1.stopPropagation();
  287.          dispatchEvent(new TextEvent(TextEvent.TEXT_INPUT,true,false,param1.text));
  288.       }
  289.       
  290.       override protected function configUI() : void
  291.       {
  292.          super.configUI();
  293.          tabChildren = true;
  294.          textField = new TextField();
  295.          addChild(textField);
  296.          updateTextFieldType();
  297.          textField.addEventListener(TextEvent.TEXT_INPUT,handleTextInput,false,0,true);
  298.          textField.addEventListener(Event.CHANGE,handleChange,false,0,true);
  299.          textField.addEventListener(KeyboardEvent.KEY_DOWN,handleKeyDown,false,0,true);
  300.       }
  301.       
  302.       public function setSelection(param1:int, param2:int) : void
  303.       {
  304.          textField.setSelection(param1,param2);
  305.       }
  306.       
  307.       public function get displayAsPassword() : Boolean
  308.       {
  309.          return textField.displayAsPassword;
  310.       }
  311.       
  312.       public function appendText(param1:String) : void
  313.       {
  314.          textField.appendText(param1);
  315.       }
  316.       
  317.       public function set restrict(param1:String) : void
  318.       {
  319.          if(componentInspectorSetting && param1 == "")
  320.          {
  321.             param1 = null;
  322.          }
  323.          textField.restrict = param1;
  324.       }
  325.       
  326.       public function get htmlText() : String
  327.       {
  328.          return textField.htmlText;
  329.       }
  330.       
  331.       protected function drawBackground() : void
  332.       {
  333.          var _loc1_:DisplayObject = null;
  334.          var _loc2_:String = null;
  335.          _loc1_ = background;
  336.          _loc2_ = !!enabled ? "upSkin" : "disabledSkin";
  337.          background = getDisplayObjectInstance(getStyleValue(_loc2_));
  338.          if(background == null)
  339.          {
  340.             return;
  341.          }
  342.          addChildAt(background,0);
  343.          if(_loc1_ != null && _loc1_ != background && contains(_loc1_))
  344.          {
  345.             removeChild(_loc1_);
  346.          }
  347.       }
  348.       
  349.       override public function setFocus() : void
  350.       {
  351.          stage.focus = textField;
  352.       }
  353.       
  354.       protected function drawLayout() : void
  355.       {
  356.          var _loc1_:Number = NaN;
  357.          _loc1_ = Number(getStyleValue("textPadding"));
  358.          if(background != null)
  359.          {
  360.             background.width = width;
  361.             background.height = height;
  362.          }
  363.          textField.width = width - 2 * _loc1_;
  364.          textField.height = height - 2 * _loc1_;
  365.          textField.x = textField.y = _loc1_;
  366.       }
  367.       
  368.       public function set maxChars(param1:int) : void
  369.       {
  370.          textField.maxChars = param1;
  371.       }
  372.       
  373.       public function get maxHorizontalScrollPosition() : int
  374.       {
  375.          return textField.maxScrollH;
  376.       }
  377.       
  378.       protected function drawTextFormat() : void
  379.       {
  380.          var _loc1_:Object = null;
  381.          var _loc2_:TextFormat = null;
  382.          var _loc3_:TextFormat = null;
  383.          _loc1_ = UIComponent.getStyleDefinition();
  384.          _loc2_ = !!enabled ? _loc1_.defaultTextFormat as TextFormat : _loc1_.defaultDisabledTextFormat as TextFormat;
  385.          textField.setTextFormat(_loc2_);
  386.          _loc3_ = getStyleValue(!!enabled ? "textFormat" : "disabledTextFormat") as TextFormat;
  387.          if(_loc3_ != null)
  388.          {
  389.             textField.setTextFormat(_loc3_);
  390.          }
  391.          else
  392.          {
  393.             _loc3_ = _loc2_;
  394.          }
  395.          textField.defaultTextFormat = _loc3_;
  396.          setEmbedFont();
  397.          if(_html)
  398.          {
  399.             textField.htmlText = _savedHTML;
  400.          }
  401.       }
  402.       
  403.       protected function handleChange(param1:Event) : void
  404.       {
  405.          param1.stopPropagation();
  406.          dispatchEvent(new Event(Event.CHANGE,true));
  407.       }
  408.    }
  409. }
  410.